import Vue from "vue";
import App from "./App.vue";
import { Header,Button } from 'mint-ui';



//图片预览插件
// import VuePreview from 'vue-preview';
// Vue.use(VuePreview);
import VuePreview from 'vue-preview'
            //使用vue-preview
Vue.use(VuePreview)
console.log('-------------------');
console.log(VuePreview);
Vue.component(Header.name, Header);
Vue.component(Button.name, Button);
import { Swipe, SwipeItem } from 'mint-ui';
Vue.component(Swipe.name, Swipe);
Vue.component(SwipeItem.name, SwipeItem);
import { Lazyload } from 'mint-ui';
Vue.use(Lazyload);
import "./lib/mui/css/mui.css";





import VueRouter from "vue-router";
Vue.use(VueRouter);
import VueResource from "vue-resource";
Vue.use(VueResource);
import router from "./router.js"


//状态管理vuex的引入
import Vuex from 'vuex';
Vue.use(Vuex);
let carStr = window.localStorage.getItem('car') || '[]';
let car = JSON.parse(carStr);
const store = new Vuex.Store({
  state:{
    car:car
  },
  mutations:{
    addToCar(state,obj){
      let flag = true;
      state.car.some(item=>{
        if(item.id === obj.id){
          item.count = obj.count;
          flag = false;
          return;
        }
      })
      if(flag == true){
        state.car.push(obj);
      }
      window.localStorage.setItem('car',JSON.stringify(state.car));
    }
  },
  getters:{
    getAllCount(state){
      let countAll = 0;
      state.car.forEach(item=>{
        countAll += item.count;
      })
      return countAll;
    }
  }
})

new Vue({
  el:"#app",
  render:c=>c(App),
  router,
  store
})